using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Collections;

namespace MyCollections.Model
{
    [Serializable]
    [XmlRoot(Namespace = null, ElementName = "Collection")]    
    public class Collection
    {
        public Collection() {
            movies = new ArrayList();
        }

        private ArrayList movies;

        public Movie[] Movies
        {
            get
            {
                Movie[] m = new Movie[movies.Count];
                movies.CopyTo(m);
                return m;
            }
            set
            {
                if (value == null) return;
                Movie[] m = (Movie[])value;
                movies.Clear();
                foreach (Movie mo in m)
                    movies.Add(mo);
            }

        }

        public void addMovie(Movie mov)
        {
            movies.Add(mov);
        }

        public void addMovies(Movie[] mov)
        {
            movies.AddRange(mov);
        }

        public Movie findMovie(string title)
        {
            foreach (Movie m in movies)
            {
                if (m.Title.ToLower().Contains(title.ToLower()))
                    return m;
            }
            return null;
        }
    }
}
